package com.gdth.bank.presenter;

import java.util.List;

import com.gdth.bank.bean.ContactBean;
import com.gdth.bank.model.ContactModel;
import com.gdth.bank.view.ContactView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class ContactPresenter {
	private ContactView mContactView;
	private ContactModel mContactModel;
	
	public ContactPresenter(ContactView mContactView){
		this.mContactView = mContactView;
		mContactModel = new ContactModel();
		
	}
	
	public void getContactList(){
		mContactModel.getContactList()
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<List<ContactBean>>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mContactView.showMessage("获取通讯录成功");
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mContactView.showMessage("获取通讯录失败");
				}

				@Override
				public void onNext(List<ContactBean> arg0) {
					// TODO Auto-generated method stub
					mContactView.updateContacts(arg0);
				}});
	}
}
